//
//  Element3D_FixedPoints.cpp
//  C3W_Demo_By_Fan
//
//  Created by 范静涛 on 2024/7/23.
//

//------------------------------------------------------------------------------
//【文件名】Element3D_FixedPoints.cpp
//【功能模块和目的】固定点数量的三维基元类实现
//【开发者及日期】范静涛 2024/7/23
//【更改记录】
//------------------------------------------------------------------------------

#include "Element3D_FixedPoints.hpp"
#include <cstddef>
#include <stdexcept>
#include <string>
#include <vector>

//------------------------------------------------------------------------------
//内嵌异常类
//------------------------------------------------------------------------------

//函数名：Element3D_FixedPoints
//功能：COUNT_IS_DIFFERENT异常类构造函数
//入口参数：无
//出口参数：无
//返回值：无
Element3D_FixedPoints::COUNT_IS_DIFFERENT::COUNT_IS_DIFFERENT()
: std::invalid_argument(
    std::string("Un-duplicate points'count is different")){
}
//------------------------------------------------------------------------------

//函数名：POINT_COUNT_IS_FIXED
//功能：POINT_COUNT_IS_FIXED异常类构造函数
//入口参数：无
//出口参数：无
//返回值：无
Element3D_FixedPoints::POINT_COUNT_IS_FIXED::POINT_COUNT_IS_FIXED()
: std::logic_error(std::string("Point's count can't be changed")){
}
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
//必要的构造、析构、赋值行为
//------------------------------------------------------------------------------

//函数名：Element3D_FixedPoints
//功能：默认构造函数。InitList包含不重复点数与MaxPointCount不符，则抛出异常。
//     手动触发基类带参构造
//入口参数：const std::vector<Point3D>& InitList, size_t MaxPointCount
//出口参数：无
//返回值：无
Element3D_FixedPoints::Element3D_FixedPoints
(const std::vector<Point3D>& InitList, size_t MaxPointCount)
: Element3D(MaxPointCount){
    //InitList包含点数与MaxPointCount不符，则抛出异常
    if (InitList.size() != MaxPointCount) {
        throw COUNT_IS_DIFFERENT();
    }
    //按基类规则添加点
    for (auto P : InitList) {
        this->Element3D::AppendPointByRule(P);
    }
    //InitList包含不重复点数与MaxPointCount不符，则抛出异常
    if (Points.Count != MaxPointCount) {
        throw COUNT_IS_DIFFERENT();
    }
}
//------------------------------------------------------------------------------

//函数名：Element3D_FixedPoints
//功能：拷贝构造函数，手动触发基类拷贝构造
//入口参数：const Element3D_FixedPoints& Source
//出口参数：无
//返回值：无
Element3D_FixedPoints::Element3D_FixedPoints
(const Element3D_FixedPoints& Source) : Element3D(Source){
}
//------------------------------------------------------------------------------

//函数名：operator=
//功能：赋值运算符overload。手动调用基类赋值运算符，赋值基类部分
//入口参数：const Element3D_FixedPoints& Source
//出口参数：无
//返回值：基元自身的引用
Element3D_FixedPoints& Element3D_FixedPoints::operator=
 (const Element3D_FixedPoints& Source){
    if (this != &Source) {
        this->Element3D::operator=(Source);
    }
    return *this;
}
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
//受保护 非静态Setter成员函数
//------------------------------------------------------------------------------

//函数名：AppendPointByRule
//功能：按规则添加点override。本类实现为不可添加
//入口参数：const Point3D& APoint
//出口参数：无
//返回值：无
void Element3D_FixedPoints::AppendPointByRule(const Point3D& APoint){
    throw POINT_COUNT_IS_FIXED();
}
//------------------------------------------------------------------------------

//函数名：RemovePointByRule
//功能：按规则删除点override。本来实现为不可删除
//入口参数：const Point3D& APoint
//出口参数：无
//返回值：无
void Element3D_FixedPoints::RemovePointByRule(const Point3D& APoint){
    throw POINT_COUNT_IS_FIXED();
}
//------------------------------------------------------------------------------

//函数名：ClearByRule
//功能：按规则清空基元override。本来实现为不可清空
//入口参数：无
//出口参数：无
//返回值：无
void Element3D_FixedPoints::ClearByRule(){
    throw POINT_COUNT_IS_FIXED();
}
//------------------------------------------------------------------------------
